package org.eleorc.ioc.annotationbased.value;

import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.GenericConverter;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class MyCustomConverter implements Converter<String, Movie> {

    @Override
    public Movie convert(String source) {
        Movie movie = new Movie();
//        movie.setName("aaa");
//        movie.setPlayers(Arrays.asList("lobbin","nami"));
        String[] split = source.split(":");
        String name = split[0];
        String playerListStr = split[1];  // [aaa,bbb]
        movie.setName(name);
        String[] playersArr = playerListStr.substring(1, playerListStr.length() - 1).split(",");
        List<String> list = Arrays.asList(playersArr);
        movie.setPlayers(list);
        return movie;
    }

}
